package com.example.shop.controller;

import com.example.common.model.vo.FileVO;
import com.example.common.utils.MinioUtils;
import com.example.shop.mapper.GoodsImageMapper;
import jakarta.websocket.server.PathParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2025/9/2 21:53
 **/
@RestController
@RequestMapping("/api/shop")
@RequiredArgsConstructor
public class ShopController {
    private final MinioUtils minioUtils;
    private final GoodsImageMapper goodsImageMapper;

    @GetMapping("/file")
    public FileVO getFile(@PathParam("fileId") String fileId) {
        // "苹果转场.mp4"
        String dbFileId = goodsImageMapper.queryGoodsImageDefault();
        if (dbFileId.contains("https")) {
            return FileVO.builder().url(dbFileId).build();
        } else {
            String url = minioUtils.getObjectUrl(dbFileId);
            return FileVO.builder().url(url).build();
        }
    }
}
